package common

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"github.com/stretchr/testify/assert"
	"os"
	"testing"
	"time"
)

func TestLogFormatter(t *testing.T) {
	logrus.SetFormatter(&logrus.TextFormatter{
		ForceQuote:      true,
		TimestampFormat: time.DateTime,
	})

	logrus.Info("info msg")
	logrus.Warn("warn msg")
	logrus.Trace("trace msg")
	logrus.Debug("debug msg")
	logrus.Error("error msg")
	//logrus.Fatal("fatal msg")
	//logrus.Panic("panic msg")
}

func TestReadEntity(t *testing.T) {
	_, err := ParseConfig("")
	assert.Error(t, err, os.ErrNotExist)
	config, err := ParseConfig(GlobalDefaultConfigPath)
	assert.Equal(t, err, nil)
	//tt, err := time.Parse(time.DateOnly, config.BaseConfig.TimeStampString)
	assert.Equal(t, err, nil)
	fmt.Println(config.BaseConfig)
	fmt.Println(config.IncludeRepos)
	fmt.Println(config.ExcludeRepos)

	nt := time.Now()
	assert.Equal(t, config.BaseConfig.TimeStamp.Before(nt), true)
	//fmt.Println(config.IncludeRepos[1].PrivateToken)
	//assert.Equal(t, 0, len(config.IncludeRepos[1].PrivateToken))
}

func TestChannel(t *testing.T) {
	ch := make(chan int, 10)

	for i := 0; i < 5; i++ {
		ch <- i // 发送数据到channel
	}
	close(ch) // 关闭channel

	// 遍历已关闭的channel
	for val := range ch {
		fmt.Println(val)
	}
}

func TestTime(t *testing.T) {
	timeStamp, err := time.Parse(time.DateOnly, "2023-10-10")
	assert.Equal(t, err, nil)
	fmt.Println(timeStamp)

	fmt.Println(time.Now().Format(time.DateOnly))
	fmt.Println(timeStamp.After(time.Now()))
	fmt.Println(timeStamp.Before(time.Now()))
}
